<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>OA协同办公系统</title>
<link href="css/table.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="js/openwindow.js"></script>
<script type="text/javascript" src="js/file.js"></script>
<style type="text/css">
body{margin: 0}
.ulemail{ list-style:none; margin:0; margin-left:20px}
.ulemail li{ font-size:12px; color:#8fa1af}
.ulxz{list-style:none; margin:5px 0 0 0}
.ulxz li{float:left; margin-left:15px}
</style>
<script type="text/javascript">
var editor;
KindEditor.ready(function(K) {
	editor = K.create('textarea[name="content"]', {
		themeType : 'simple',
		resizeType : 1,
		allowPreviewEmoticons : false,
		allowImageUpload : false,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link','print','link','unlink']
		});
	});
	
	$(function(){
		$.post("getTemplate.action",null,function(data){
			var list =data.tempObjectList;
			var fnfoot="";
			var info="<option value='选择' >选择</option>";
			for(var i=0;i<list.length;i++){
				var obj = list[i];
				info+="<option value=\""+i+"\">"+obj[1]+"</option>";
				fnfoot+="<input type='hidden' value='"+obj[4]+"' id='"+i+"' /> ";
			}
			$("#template").html(info);
			$("#info_2").html(fnfoot);
		},"json");
	});
	
	function selectUser(){
		var url="getGrouphome.action";
		openWindow(url,700,400);
	}
	function getOldValue(){
	  var array = document.getElementById("array").value;
	  return array;
	}
	
	function setValue(value){
	  document.getElementById("array").value = value;
	  var arr = eval(value);
	  var names = "";
	  var ids = "";
	  for(i=0;i<arr.length;i++){
	    ids =  ids + "," + arr[i].value;
	    names = names + "," + arr[i].name;
	  }
	  if(names.length>0){
	    names = names.substring(1);
	    ids =  ids.substring(1);
	  }
	  document.getElementById("names").value=names;
	  document.getElementById("ids").value=ids;
	}
	
	function updatereport(){
		var content =editor.html();
		var users =$("#names").val();
		var note=$("#note").val()
		if(users=='' || users=='null'){
			alert("请添加联系人");
			return;
		}
		if(editor.isEmpty()){
			alert("请填写内容");
			return;
		}else if(content.length>2000){
			alert("正文不能超过2000个字符！");
			return;
		}
		if(note>500){
			alert("正文不能超过500个字符！");
			return;
		}
		var table=$("#filetable").find("input[type=\"checkbox\"]");
		var fileId="";
		for(var i=0;i<table.length;i++){
			fileId+="_"+table[i].value;
		}
		$("#fileArray").val(fileId);
		$("#content").val($.trim(content));
		document.reportForm.action="updateReport.action";
		document.reportForm.submit();
		window.close();
		var currentPage=$("#currentPage").val();
		window.opener.page(currentPage);
	}
	
	function loadFile(val){
		var fileId=$("#fileArray").val();
		if(fileId!=''&&fileId!='null'){
			var param={"fileArray":fileId};
			$.post("getFileList.action",param,function(data) {
				var list=data.fileList;
				for(var i=0;i<list.length;i++){
					$("#"+val).prepend("<tr><td><input type=\"checkbox\" name=\"checkbox2\" id=\""+list[i].id+"\" value=\""+list[i].id+"\" />&nbsp;<a href=\"downLoadFile.action?fileId="+list[i].id+"\">"+list[i].name+"</a>&nbsp;</tr>");
		        }
			},"json");
		}
		var status=$("#status").val();
		var radio=$("input[type=\"radio\"]");
		for(var i=0;i<radio.length;i++){
			if(radio[i]==status){
				radio[i].checked=true;
				break;
			}
		}
	}
	window.onload=function(){
		loadFile('filetable');
	}
	
	function select(obj){
		editor.html('');
		var a =$("#template").val();
		if(a!='选择'){
			var c = $("#"+a).val();
			editor.appendHtml(c);
			$("#tempName").val(obj.options[obj.selectedIndex].text);
		}
	}
</script>
</head>
<body>
<input type="hidden" id="currentPage" value="${currentPage}">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="98%">
  <tbody>
  <tr>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
    <td style="background: url('image/wsoa_window_002.gif');"><table border="0" cellpadding="0" cellspacing="0">
      <tbody><tr>
        <td align="center" style="background: url('image/wsoa_window_002.gif');" width="10"><img src="image/center_19.gif"></td>
        <td align="center" style="background: url('image/wsoa_window_002.gif');"></td>
        <td></td>
        </tr>
    </tbody>
    </table></td>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
  </tr>
  <tr>
    <td style="background: url('image/wsoa_window_010.gif');"  width="1">&nbsp;</td>
    <td>
    <form action="" method="post" name="reportForm">
    	<input type="hidden" id="fileArray" name="fileArray" value="${oMyReports.fileId}">
		<input type="hidden" id="array" >
		<span id="info_2"></span>
		<input type="hidden" name="tempName" id="tempName" >
		<input type="hidden" id="id" name="id" value="${oMyReports.id}">
    	<table style="margin: 5px 5px 5px 5px;width: 100%" cellpadding="5">
    	<tr>
	    	<td>类型：</td><td>
	    	<select name="type" onchange="">
		    	<option>日报</option>  
		    	<option>周报</option>  
		    	<option>月报</option>  
		    	<option>年度报</option>  
	    	</select>
	    	</td>
	    	<td>&nbsp;&nbsp;
	    	模版： <select onchange="select(this)" id="template" style="width: 100px">
	    		</select>
	    	</td>
	    </tr>
    	<tr><td valign="middle">提交：</td><td colspan="2">
    	<textarea readonly="readonly" id="names" name="names" style="width:525px;height:auto;">${names}</textarea><br/>
    	<input type="hidden" id="ids" name="users" value="${users}">
    	<a href="javascript:selectUser()">添加联系人</a></td></tr>
    	<tr><td>附件：</td><td colspan="2"><a href="javascript:file_upload('filetable')">添加附件</a>&nbsp;&nbsp;<a href="javascript:fileDel('filetable')">删除</a>
    	</td></tr>
    	<tr>
    	<td>&nbsp;</td><td colspan="2">
   			<table id="filetable" style="width:500px">
				
			</table>
    	</td>
    	</tr>
    	<tr><td>汇报内容：</td><td colspan="2"></td></tr>
    	<tr><td colspan="3">
    		<textarea name="content" id="content" style="width:600px;height:200px;visibility:hidden;">${oMyReports.content}</textarea>
    	</td></tr>
    	<tr><td>备注：</td><td colspan="2"><textarea name="note" style="width: 525px;height: 80px">${oMyReports.note }</textarea> </td></tr>
    	</table>
    	<table align="center">
    	    	<tr><td><input onclick="updatereport()" class="button_02" type="button" value="修改" />&nbsp;&nbsp;<input class="button_02" type="button" value="退出" onclick="window.close();" /> </td></tr>
    	</table>
    	</form>
    </td>
    <td style="background: url('image/wsoa_window_006.gif');"  width="1">&nbsp;</td></tr>
  <tr>
    <td height="1" width="1"><img src="image/wsoa_window_009.gif" height="16" width="14"></td>
    <td style="background: url('image/wsoa_window_008.gif');" height="1"></td>
    <td height="1" width="1"><img src="image/wsoa_window_007.gif" height="16" width="12"></td>
  </tr>
</tbody>
</table>
</body>
</html>